package com.nbcio.pm.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.nbcio.common.tenant.core.TenantEntity;
import com.nbcio.pm.domain.vo.PmProjectMemberVo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDate;

/**
 * 项目成员对象 pm_project_member
 *
 * @author nbacheng
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pm_project_member")
@AutoMapper(target = PmProjectMemberVo.class, reverseConvertGenerate = false)
public class PmProjectMember extends TenantEntity {

    /**
     * ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 成员ID（别名，与id相同）
     */
    @TableField(exist = false)
    private Long memberId;

    /**
     * 项目ID
     */
    @TableField("project_id")
    private Long projectId;

    /**
     * 用户ID（多个用户用逗号分隔）
     */
    @TableField("user_id")
    private String userId;

    /**
     * 角色：manager-项目经理，developer-开发人员，tester-测试人员，observer-观察者
     */
    @TableField("role")
    private String role;

    /**
     * 权限配置（JSON格式）
     */
    @TableField("permissions")
    private String permissions;

    /**
     * 加入日期
     */
    @TableField("join_date")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate joinDate;

    /**
     * 离开日期
     */
    @TableField("leave_date")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate leaveDate;

    /**
     * 是否激活
     */
    @TableField("is_active")
    private Boolean isActive;

    /**
     * 成员状态（0：非活跃，1：活跃）
     */
    @TableField("status")
    private String status;

    /**
     * 备注
     */
    @TableField("remark")
    private String remark;

    /**
     * 排序
     */
    @TableField("sort_order")
    private Integer sortOrder;

    // 关联字段（非数据库字段）
    @TableField(exist = false)
    private String userName;

    @TableField(exist = false)
    private String nickName;

    @TableField(exist = false)
    private String avatar;

    @TableField(exist = false)
    private String deptName;

    /**
     * 获取成员ID（与id相同）
     */
    public Long getMemberId() {
        return this.id;
    }

    /**
     * 设置成员ID（同时设置id）
     */
    public void setMemberId(Long memberId) {
        this.memberId = memberId;
        this.id = memberId;
    }
}
